package com.zabra.zl.ui.bargain.tab.day;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.jwenfeng.library.pulltorefresh.PullToRefreshLayout;
import com.zabra.zl.Config;
import com.zabra.zl.R;
import com.zabra.zl.base.BaseMvpFragment;
import com.zabra.zl.data.OrderListBean;
import com.zabra.zl.myview.state_layout.OtherView;
import com.zabra.zl.ui.bargain.tab.day.contract.TabDayContract;
import com.zabra.zl.ui.bargain.tab.day.presenter.TabDayPresenter;
import com.zabra.zl.utils.DialogUtils;
import com.zabra.zl.utils.ShowDialogUtils;
import com.zabra.zl.utils.ToastUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

@SuppressLint("ValidFragment")
public class TabDay extends BaseMvpFragment<TabDayPresenter> implements TabDayContract.View {
    @BindView(R.id.recycler_title)
    RecyclerView recyclerTitle;
    @BindView(R.id.recycler)
    RecyclerView recycler;
    @BindView(R.id.otherview)
    OtherView otherview;
    private List<String> titleList = new ArrayList<>();
    private List<OrderListBean.RespDataBean> list;
    private AdpTitle adpTitle;
    private Adp adp;
    private int orderId;
    private Dialog dialog;

    public TabDay(int orderId) {
        this.orderId = orderId;
    }

    @Override
    protected void initView(View view) {
        otherview.setHolder(mHolder);
        mPresenter=new TabDayPresenter();
        mPresenter.attachView(this);
        mPresenter.getData(4, orderId, "", "");

    }

    @Override
    protected int getLayoutId() {
        return R.layout.tab_day_bargain;
    }

    @Override
    public void showLoading() {
        dialog = DialogUtils.showDialog_progressbar(getActivity());
    }

    @Override
    public void hideLoading() {
        DialogUtils.closeDialog(dialog);
    }

    @Override
    public void onError(Throwable throwable) {
        DialogUtils.closeDialog(dialog);
    }

    @Override
    public void onSuccess(OrderListBean bean) {
        if (bean.getRespCode().equals(Config.SUCCESS)) {
            list = bean.getRespData();
            if (list.size() == 0) {
                otherview.showEmptyView();
            } else {
                otherview.showContentView();
                //右边内容
                recycler.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));
                recycler.setNestedScrollingEnabled(false);
                adp = new Adp(R.layout.item_bargain, list);
                recycler.setAdapter(adp);
                adp.openLoadAnimation();
                for (OrderListBean.RespDataBean respDataBean : list) {
                    titleList.add(respDataBean.getSharesCode());
                }
                //左边标签
                recyclerTitle.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));
                recyclerTitle.setNestedScrollingEnabled(false);
                adpTitle = new AdpTitle(R.layout.item_bargain_title, titleList);
                recyclerTitle.setAdapter(adpTitle);
                adpTitle.openLoadAnimation();
            }

        } else if (bean.getRespCode().equals(Config.TOKENOUT)) {
            ShowDialogUtils.restLoginDialog(getActivity());
        } else {
            ToastUtil.showToast(getActivity(), bean.getRespDesc());
        }

    }


}
